import os

from PIL import Image

PATH = r'./images_from_wu'
# PATH1 = r'D:\库\Chrome_Download\1kkk-master\1kkk\images\test\test1'
# PATH2 = r'D:\库\Chrome_Download\1kkk-master\1kkk\images\test\test2'
# PATH3 = r'D:\库\Chrome_Download\1kkk-master\1kkk\images\test\test3'


def rename(pre_name_):
    """重命名文件"""

    num = 1
    for image_old_name in os.listdir(PATH):
        new_name = f'{pre_name_}_img{num}.png'
        os.rename(os.path.join(PATH, image_old_name), os.path.join(PATH, new_name))  # 文件重命名
        num += 1
        print(image_old_name, "has been renamed successfully! New name is: ", new_name)  # 输出提示


def rotate_img(image_old_name, image_new_name):
    """图片90旋转"""

    # 读取图像
    img = Image.open(image_old_name)
    # 指定逆时针旋转的角度
    im_rotate = img.rotate(90)
    # 保存旋转后的图片
    im_rotate.save(image_new_name)


def main():
    """主函数"""

    for image_old_name in os.listdir(PATH):
        if image_old_name[1] == '2':
            image_new_name = 't3' + image_old_name[2:]
            rotate_img(os.path.join(PATH, image_old_name), os.path.join(PATH, image_new_name))


if __name__ == '__main__':
    main()
    # rename('t0')
